package logic

import (
	"context"
	"gorm.io/gorm"
	"work-safety/models/mysql"

	"work-safety/workrpc/internal/svc"
	"work-safety/workrpc/workrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductListLogic {
	return &ProductListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProductListLogic) ProductList(in *workrpc.ProductListRequest) (*workrpc.ProductListResponse, error) {
	// todo: add your logic here and delete this line
	product := mysql.Product{
		Model: gorm.Model{ID: uint(in.ProductId)},
	}

	return &workrpc.ProductListResponse{
		Title:        product.Title,
		Price:        float32(product.Price),
		Address:      product.Address,
		ProductImage: product.ProductImage,
		UserId:       int64(product.UserId),
	}, nil
}
